<?php
load::model('cliente');
class ClienteController extends AppController {
     public function before_filter() {
        if ( !Auth::is_valid()){
            Router::redirect('usuario/login/');
        }else{
            $this->tipoMenu="cliente";
        }
    }
    
    public function index(){
        
    }
    
    public function agregar(){
        if(Input::hasPost('cliente')){
           
            $cliente = new Cliente(Input::post('cliente'));
            
             if(!$cliente->save()){
                Flash::error('Error al agregar CLiente');
                
                $this->categoria = $this->post('cliente');
              
            }else{
                Flash::success('Cliente agregado satisfactoriamente');
            }
        }
    }
    public function listar(){
         $cliente = new Cliente();
        $this->cliente =   $cliente->find("order: nombre","conditions: estado=1"); 
        
    }
    public function eliminar($id){
            $cliente = new Cliente();
            $cliente = $cliente->find($id);
            $cliente->estado = "0";
            
            if ($cliente->update()) {
                Flash::valid('Operación exitosa');
            }else{
                Flash::error('Falló Operación'); 
            }
 
            return Router::redirect('cliente/listar');
        }
}
    